<?
	include ("conn.php");
	
	$db_selected = $_POST['db'];

	if($db_selected == ''){
		$db_selected = $_GET['db'];
	}	
	
	$db = get_conn($db_selected);
	
	
	$sql ="SHOW DATABASES";
	$result = mysql_query($sql);
	if($result){
			$dbs .="  <option value=''>Select</option>";

		while ($row = mysql_fetch_array($result)){
			$dbs .="  <option value='".$row[0]."' ".getstatus($_GET['db'],$row[0]).">".$row[0]."</option>";
		}
	}else{
		error_handling(__FUNCTION__.$sql,mysql_error());
	}
	
	
	if($_GET['db'] !=''){
		$sql ="show tables from ".$_GET['db'];
		$result = mysql_query($sql);
		if($result){
			while ($row = mysql_fetch_array($result)){

				if($_GET['tabla'] == $row[0] ){
					$status = " selected ";
				}else{
					$status = " ";
				}
				
				$tablas .="  <option value='".$row[0]."' ".$status.">".$row[0]."</option>";
			}
		}else{
			error_handling(__FUNCTION__.$sql,mysql_error());
		}
	}else{
			$tablas .="  <option value=''>Select the database</option>";
	}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Source Generator</title>
<style type="text/css">
<!--
body {
	background-attachment: scroll;
	background-image: url(bg.jpg);
	background-repeat: repeat-x;
	background-position: left top;
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 11px;
	color: #4A6D80;
	text-decoration: none;
	margin-top: 65px;
	margin-right: 0px;
	margin-bottom: 0px;
	margin-left: 0px;
	font-weight: normal;
	background-color: #4A6C7F;
}
#loginContainer {
	height: 522px;
	width: 451px;
	
	margin-left: auto;
	background-image: url(login_bg.jpg);
	background-repeat: no-repeat;
	margin-right: auto;
	margin-top: 0px;
	margin-bottom: 0px;
}
#login {
	padding-top: 150px;
	text-align: right;
	padding-right: 150px;
}
p {
	margin: 0px;
}
.textfield {
	height: 16px;
	border-right-width: 1px;
	border-bottom-width: 1px;
	border-right-style: solid;
	border-bottom-style: solid;
	border-bottom-color: #ABC1CD;
	border-right-color: #ABC1CD;
	font-family: Arial;
	font-size: 10px;
	font-weight: bold;
	color: #999999;
	text-decoration: none;
	width: 120px;
	padding-top: 3px;
	padding-bottom: 1px;
	padding-left: 5px;
	border-top-width: 0px;
	border-left-width: 0px;
	border-top-style: none;
	border-left-style: none;
}
-->
</style>

<script>
	function show_tables(db){
		document.location.href='?db='+db;
	}
</script></head>
<body>
<div id="loginContainer">
<form style="display: inline;" name="loginform"  action="gen.php" method="post" >
<div id="login">
  <table width="30%" border="0" class="table" align="center">
      <tr>
        <td  align="center"><div align="left">BD</div></td>
        <td  align="center"><div align="left">
            <select name="db"  onchange="show_tables(this.value)">
              <? echo $dbs ;?>
            </select>
        </div></td>
      </tr>
      <tr>
        <td width="47%"  align="center"><div align="left">Tabla </div></td>
        <td width="47%"  align="center"><div align="left">
            <select name="tabla">
              <? echo $tablas ;?>
            </select>
        </div></td>
      </tr>
      <tr>
        <td align="center"><div align="left">Generar</div></td>
        <td align="center" nowrap="nowrap">
          <div align="left">
              <input type="radio" name="gtipo" id="radio" value="PHP" />
            Mantenimiento            </div></td>
      </tr>
      <tr>
        <td align="center"  >&nbsp;</td>
        <td align="center"  ><div align="left">
              <input name="gtipo" type="radio" id="radio2" value="HTML" checked="checked" />
          HTML</div></td>
      </tr>
      <tr>
        <td align="center"  ><div align="left"></div></td>
        <td align="center"  ><div align="left">
          <input name="gtipo" type="radio" id="radio3" value="POST" checked="checked" />
          POST </div></td>
      </tr>
      <tr>
        <td align="center" colspan="2"  ><input type="submit" name="Submit" value="Crear" /></td>
      </tr>
    </table>
    <p>&nbsp;</p>
    <p></p>
  </div>
</form>
</div>
</body>
</html>